<template>
<div>
  <vheader></vheader>
  <loading v-if="loading"></loading>
  <div class="MovieList" v-if="!loading">
    <div class="movies" v-for="movie in MovieList" v-on:click="gotoDetail(movie.id)">
      <div class="movie">
        <div class="poster">
          <img :src="movie.images.small">
        </div>
        <div class="movieMsg">
          <h2>{{movie.title}}</h2>
          <star :num="movie.rating.stars"></star>
          <p>{{movie.rating.average}}分</p>
          <p>导演:
            <span v-for="directors in movie.directors">{{directors.name}} &nbsp;</span>
          </p>
          <p>主演:
            <span v-for="casts in movie.casts">{{casts.name}} &nbsp;</span>
          </p>
        </div>
      </div>
    </div>
  </div>
</div>
</template>

<script>
import vheader from './vheader'
import star from './star'
import loading from './loading'

export default {
  name: 'MovieList',
  data () {
    return {
      loading: true,
      MovieList: []
    }
  },
  components: {
    star,     //star: star,
    loading,  //loading: loading
    vheader: vheader   
  },
  mounted() {
    this.$http.jsonp("https://api.douban.com//v2/movie/in_theaters").then(function(response) {
    // this.$http.get("http://localhost:8080/static/data.json").then(function(response) {
        this.MovieList = response.body.subjects;
        this.loading = false
    })
  },
  filters: {
    capitalize: function (value) {
     return value.substr(0,5)
    }
  },
  methods: {
    gotoDetail:function(id) {
      this.$router.push({name:'MovieDetail', params: {id:id}})
    }
  }
}

</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>


.movies{
  overflow: hidden;
  padding: 10px 20px;
  background-color: #f8f8f8;
}
.movie{
  overflow: hidden;
  padding-bottom: 10px;
  background-color: #f8f8f8;
  border-bottom: 1px solid #d6d6d6;
  display: flex;
}
.poster{
  flex: 1;
  margin-top: 20px;
  padding-right: 10px;
}
.movieMsg{
  flex: 4;
  margin-left: 10px;
}
.movieMsg h2{
  font-size: 20px;
  font-weight: 500;
  margin-bottom: 10px;
  line-height: 30px;
}
.movieMsg p{
  font-size: 14px;
  color: #666;
  line-height: 21px;
}
.movieMsg .stars{
  color: #fe9a03;
}
</style>
